home *** CD-ROM | disk | FTP | other *** search
- ;; Mark the buffer modifiable with ^X^Q (as others pointed out). Edit
- ;; it. Save it somewhere you can write with ^X^W (like ~/ or /tmp/).
- ;; Then use su-command (appended below) to move or copy the file over the
- ;; old version, perhaps moving the previous one out of the way first if
- ;; necessary. Elisp after my .sig.
- ;;
- ;; (anticipating the nits: yes, I know the password echos as you type it.
- ;; However, putting the two arguments in the order they are at least
- ;; overwrites the minibuffer as soon as you finish the password. Anyone
- ;; who wants to add the get-a-string-sliently logic to the following is
- ;; welcome to do it and repost).
- ;; --
- ;; /jr, nee John Robinson Life did not take over the globe by combat,
- ;; jr@bbn.com or bbn!jr but by networking -- Lynn Margulis
-
- (defun su-command (password command)
- "Prompt for root password and a command, then do the latter as root."
- (interactive "sRoot password: \nsCommand: ")
- (let ((buffer (get-buffer-create "*Shell Command Output*"))
- proc)
- (save-excursion
- (set-buffer buffer)
- (erase-buffer))
- (setq proc (start-process "su-emacs" buffer "/bin/su"
- "-c" command))
- (if (save-excursion
- (set-buffer buffer)
- (goto-char (point-min))
- (while (not (looking-at "Password:"))
- (accept-process-output proc)
- (goto-char (point-min)))
- (erase-buffer)
- (send-string proc (concat password "\n"))
- (while (not (looking-at "\n"))
- (accept-process-output proc)
- (goto-char (point-min)))
- (delete-char 1)
- (while (not (equal (process-status proc) 'exit))
- (accept-process-output))
- (> (buffer-size) 0))
- (set-window-start (display-buffer buffer) 1)
- (message "(Command completed with no output)"))))
-
- ;;; suggested binding (# is the prompt when superuser):
- ;;; (global-set-key "\e#" 'su-command)
-